package TetrisFlash.GameLoadData 
{
	import flash.display.Bitmap
	import flash.utils.Dictionary;
	
	import starling.textures.Texture;
	import starling.textures.TextureAtlas;
	/**
	 * ...
	 * @author DANTRUONG
	 */
	public class AssetsTexture 
	{
		[Embed(source = "/../media/graphics/bgWelcome.jpg")]
		public static const bgWelcome:Class;
		
		[Embed(source = "/../media/graphics/bgLayer1.jpg")]
		public static const bgLayer1:Class;
		
		private static var gameTextures:Dictionary = new Dictionary();
		private static var gameTextureAtlas:TextureAtlas;
		
		
		[Embed(source="/../media/graphics/mySpritesheet.png")]
		public static const AtlasTextureGame:Class;
		
		[Embed(source="/../media/graphics/mySpritesheet.xml", mimeType="application/octet-stream")]
		public static const AtlasXmlGame:Class;
		
		//Assets for tetris
		private static var gameAtlasTetris:TextureAtlas;
		
		[Embed(source="/../media/graphics/tetrisBrickSpriteSheet.png")]
		public static const AtlasTextureTetris:Class;
		
		[Embed(source="/../media/graphics/tetrisBrickSpriteSheet.xml", mimeType="application/octet-stream")]
		public static const AtlasXmlTetris:Class;
		
		private static var instance: AssetsTexture;
		
		public static function getAtlas():TextureAtlas {
			if (gameTextureAtlas == null)
			{
				var texture:Texture = getTexture("AtlasTextureGame");
				var xml:XML = XML(new AtlasXmlGame());
				gameTextureAtlas = new TextureAtlas(texture, xml);
			}
			return gameTextureAtlas;
		}
		
		public static function getTetrisAtlas():TextureAtlas {
			if (gameAtlasTetris == null)
			{
				var texture:Texture = getTexture("AtlasTextureTetris");
				var xml:XML = XML(new AtlasXmlTetris());
				gameAtlasTetris = new TextureAtlas(texture, xml);
			}
			return gameAtlasTetris;
		}
		
		public static function getTexture(name:String):Texture
		{
			if (gameTextures[name] == undefined)
			{
				var bitmap:Bitmap = new AssetsTexture[name]();
				gameTextures[name] = Texture.fromBitmap(bitmap);
			}
			return gameTextures[name];
		}
		
	}

}